package br.com.seuimovelnamao.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import br.com.seuimovelnamao.PropertiesLoaderImpl;

public class SessionInterceptor extends HandlerInterceptorAdapter {
	
	@Override
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler) throws Exception {
		
		String uri = request.getRequestURI();

		if(uri.contains("memberArea")){
			if(request.getSession().getAttribute("usuario") == null){
				request.getSession().setAttribute("loginError", PropertiesLoaderImpl.getValor("erro_sessao_expirada"));
				response.sendRedirect("/login");
				return false;
			}
		}

		return true;
		
	}
	
}
